	//GENERIQUE --------------------------------------------------------------------------------------------------------------------------------------------
	//------------------------------------------------------------------------------------------------------------------------------------------------------
	
	function MakeRequired(){
		if($(".required").length){
			$(".CanBeRemoved").remove();
			switch (this.type) {
				case 'radio':
				case 'checkbox':
					if($(this).is(':last-child')){
						$(".required").parent().find("label").append(" <strong class='orange CanBeRemoved'>*</strong>");
					}
					break;
				default: 
					$(".required").parent().find("label").append(" <strong class='orange CanBeRemoved'>*</strong>");
					break;
			}
		}
	}
	
	function MakeInputExemple(){
		if($("input.exemple").length){
				$("input.exemple").each(function(){
				if($(this).val()==""){
					$(this).addClass("ex").val($(this).attr("title"));
				}
				$(this).focus(function(){
				 if($(this).val()==$(this).attr("title"))
					$(this).removeClass("ex").val("");
					$(this).addClass("normal");
				});
				$(this).blur(function(){
				 if($(this).val()=="")
					$(this).addClass("ex").removeClass("normal").val($(this).attr("title"));
				});
			});
		}
	}
	
	function MakeInputToMaj(){
		if($("input.MAJUSCULE").length){
			$("input.MAJUSCULE").each(function(){						   
				$(this).change(function(){
					$(this).val($(this).val().toUpperCase());
				 });
			});
		}
	}
	
	function MakeInputToNomPropr(){
		if($("input.NOM_PROPRE").length){
			$("input.NOM_PROPRE").each(function(){						   
				$(this).change(function(){
					var st = "";
					var mots = new Array();
					mots = $(this).val().split(" ");
					for (var i in mots){
						st += " " + mots[i].charAt(0).toUpperCase() + mots[i].substring(1).toLowerCase();
					}
					$(this).val(st.substr(1));
				 });
			});
		}
	}
	
	function MakeInputToTestDate(){
		if($("input.TestDate").length){
			$("input.TestDate").each(function(){						   
				$(this).change(function(){
										
					 re = new RegExp("^[0-9]{2}/[0-9]{2}/[0-9]{4}$");
					 var OK = re.exec($(this).val());
					 if (!OK){
						if($('#lang').val()=='EN')	msg = "Date format must be DD/MM/YYYY";
						else msg = "La date doit etre a format JJ/MM/AAAA";
						alert(msg);
						$(this).val("");
						return false;
					 }
					 else{
						return true;
					 }
					
				 });
			});
		}
	}
	
	function MakeInputToTestTime(){
		if($("input.TestHeure").length){
			$("input.TestHeure").each(function(){						   
				$(this).change(function(){
										
					 re = new RegExp("^[0-9]{2}:[0-9]{2}$");
					 var OK = re.exec($(this).val());
					 if (!OK){
						if($('#lang').val()=='EN')	msg = "Time format must be HH:MM";
						else msg = "L'heure doit etre au format HH:MM";
						alert(msg);
						$(this).val("");
						return false;
					 }
					 else{
						return true;
					 }
					
				 });
			});
		}
	}
	
	function MakeInputToTestPhone(){
		if($("input.TestPhone").length){
			$("input.TestPhone").each(function(){						   
				$(this).change(function(){
										
					 re = new RegExp("^[0-9\+\(\)][0-9\. \-\(\)]+$");
					 var OK = re.exec($(this).val());
					 if (!OK){
						if($('#lang').val()=='EN')	msg = "Phone number is not valid (numeric with dot, plus, space or dash)";
						else msg = "Le numero de telephone n'est pas valide (chiffres et espaces, points ou tirets)";
						alert(msg);
						$(this).val("");
						return false;
					 }
					 else{
						return true;
					 }
					
				 });
			});
		}
	}
	
	
	function MakeInputToTestEmail(){
		if($("input.TestEmail").length){
			$("input.TestEmail").each(function(){						   
				$(this).change(function(){
										
					 re = new RegExp("^([a-zA-Z0-9_-])+([.]?[a-zA-Z0-9_-]{1,})*@([a-zA-Z0-9-_]{2,}[.])+[a-zA-Z]{2,4}$");
					 var OK = re.exec($(this).val());
					 if (!OK){
						if($('#lang').val()=='EN')	msg = "Email Address is not valid";
						else msg = "L'adresse email n'est pas valide";
						alert(msg);
						$(this).val("");
						return false;
					 }
					 else{
						return true;
					 }
					
				 });
			});
		}
	}
	
	
	function MakeBtnToValidAndTest(){
		if($(".btn").length){
		
			$(".btn").click(function () { 
				
				if($('#lang').val()=='EN'){
					var msgErreur = "Please fill following required fields\n\n";
				} else {
					var msgErreur = "Merci de renseigner les champs obligatoires\n\n";
				}
				var errors=0;
				var color_off = "#FFFFFF";
				var color_on = "#FFCCCC";
				
				$(".required").each(function(){
											 
					$(this).parent().removeClass("required_alert");
		
				});
				
				$("input").each(function(){
										 
					if($(this).val()==$(this).attr("title")) {
						$(this).val("");
					}		
					
				});
				
				$(".required").each(function(){
					
					if(!$(this).parents().hasClass("invisible")){
					
						switch (this.type) {
							
							
							case 'radio':
							case 'checkbox':
								if($('input[name=' + $(this).attr('name') + ']:checked').length == 0){
									errors++;
									if($(this).is(':last-child')){
										if($(this).parent().find("label:first").text()!="") {
											msgErreur += "- " + $(this).parent().find("label:first").text() + "\n";
										}
									}
									$(this).parent().addClass("required_alert");
								}
								break;
							
							default: 
								if(this.value == "") {
									errors++;
									if($(this).parent().find("label").text()!="") {
										msgErreur += "- " + $(this).parent().find("label:first").text() + "\n";
									}
									$(this).parent().addClass("required_alert");
									
								}
								break;
						}
					}
					
				});
				
				if(errors!=0){
					alert(msgErreur);
				}
				else{
					$(this).parents('form:first').submit();
				}
				
			});
		}
	}
	
	
	function MakeFormAction(){
		MakeRequired();
		MakeInputExemple();
		MakeInputToMaj();
		MakeInputToNomPropr();
		MakeInputToTestDate();
		MakeInputToTestTime();
		MakeInputToTestPhone();
		MakeInputToTestEmail();
		MakeBtnToValidAndTest();
	}
	
	
	//SPECIFIQUE ECF ------------------------------------------------------------------------------------------------------------------------------------
	//------------------------------------------------------------------------------------------------------------------------------------------------------
 
	
	function AjaxPassSelected(val){
			
			valPass = val;
			
			AjaxPolicyInfos(val);
			
			$.ajax({
					url: "/layouts/ajax/HotelForm.php",
					type: "POST",
					data: {ConfPassId:valPass},
					success: function(feedback){
						$('#AjaxHotelDisplayForm').html(feedback);
						$('#AjaxHotelDisplayForm').fadeIn("slow");
						if($(".AccommodationNeed").length){
							$(".AccommodationNeed").click(function(){
								MakeDateHotelRequired($(this));
							});
							ControleDateHotel();
						}
						
					}
			});
			
			$.ajax({
					url: "/layouts/ajax/BillingForm.php",
					type: "POST",
					data: {ConfPassId:valPass},
					success: function(feedback){
						$('#AjaxBillingFormDisplay').html(feedback);
						$('#AjaxBillingFormDisplay').fadeIn("slow");
						MakeFormAction();
						
						if($(".CopyForBilling").length){
							$(".CopyForBilling").click(function(){
								CopyForBilling();
							});
				
						}
					}
			});
	
			
	
		
		
	}
	
	function AjaxPolicyInfos(valPass){
			
		$('#AjaxPolicyInfos').fadeOut("slow");
		
		$.ajax({
				url: "/layouts/ajax/PolicyInfos.php",
				type: "POST",
				data: {ConfPassId:valPass},
				success: function(feedback){
					$('#AjaxPolicyInfos').html(feedback);
					$('#AjaxPolicyInfos').fadeIn("slow");
				}
		});
		
	}
	
	function CopyForBilling(){				
		$(".ToCopy").each(function(){
			MatchclassField = $(this).attr('ToCopy');
			switch (this.type) {
				case 'radio':
				case 'checkbox':
					if($(this).val()==$("." + MatchclassField).val()){
						$(this).attr("checked", true)
					}
					break;
				
				default: 
					$(this).val($("." + MatchclassField).val()).removeClass("ex").addClass("normal");
					break;
			}
			
		});
		$(".InvoiceInfosSame").val("Yes");
	}
	
	function MakeDateHotelRequired(elt){
		if(elt.val()=='Yes'){
			$(".AccommodationDateIn").addClass('required');
			$(".AccommodationDateOut").addClass('required');
			MakeRequired();
			/*$(".AccommodationDateIn.required").parent().find("label").append(" <strong class='orange CanBeRemoved'>*</strong>");
			$(".AccommodationDateOut.required").parent().find("label").append(" <strong class='orange CanBeRemoved'>*</strong>");*/
		} else {
			$(".AccommodationDateIn").removeClass('required').parent().removeClass("required_alert");
			$(".AccommodationDateOut").removeClass('required').parent().removeClass("required_alert");
			$("#HotelDates .CanBeRemoved").remove();
		}
	}
	
	function ControleDateHotel(){
			$(".AccomDate").change(function(){
				if($(".AccommodationDateIn").val() == $(".AccommodationDateOut").val()){
					alert("Please select different Accommodation Date In and Date Out");
					$(this).val('');
				}
			
			});
	}